<template>
  <div class="app-container">
    <div class="filter-container"></div>
    <org-table
      :list="list"
      :loading="loading"
      style="width: 1000px;"
      @edit="editDialog"
      @reload="getList"/>
    <el-dialog :visible.sync="dialog" :title="title" />
  </div>
</template>

<script>
import { fetchOrgList } from '../../api/org'
import OrgTable from './orgTable'

export default {
  name: 'OrgList',
  components: { OrgTable },
  data() {
    return {
      loading: true,
      dialog: false,
      title: '',
      list: [],
      classes: ['-1'],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetForm() {
      this.form = this.$options.data().form
    },
    getList() {
      this.loading = true
      fetchOrgList().then(response => {
        if (response.data.length !== 0) {
          this.$SUCCESS('获取机构列表成功')
          this.list = response.data.items
        } else {
          this.list = []
        }
        this.loading = false
      }).catch(() => {
        this.$ERROR('获取机构列表失败')
        this.loading = false
      })
    },
    editDialog(item) {
      this.resetForm()
      this.$setDialog(true, item.name, true)
      this.form = JSON.parse(JSON.stringify(item))
    }
  }
}
</script>

<style scoped>

</style>
